// Funciones Generales
var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
/**
* Eval script fragment
* @return String
*/
String.prototype.evalScript = function()
{
        return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
};
/**
* strip script fragment
* @return String
*/
String.prototype.stripScript = function()
{
        return this.replace(new RegExp(tagScript, 'img'), '');
};
/**
* extract script fragment
* @return String
*/
String.prototype.extractScript = function()
{
        var matchAll = new RegExp(tagScript, 'img');
        return (this.match(matchAll) || []);
};
/**
* Eval scripts
* @return String
*/
Array.prototype.evalScript = function(extracted)
{
        var s=this.map(function(sr){
                 var sc=(sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
                 if(window.execScript){
                      window.execScript(sc);
                 }
                else
               {
                   window.setTimeout(sc,0);
                }
        });
        return true;
};
/**
* Map array elements
* @param {Function} fun
* @return Function
*/
Array.prototype.map = function(fun)
{
        if(typeof fun!=="function"){return false;}
        var i = 0, l = this.length;
        for(i=0;i<l;i++)
        {
                fun(this[i]);
        }
        return true;
};

function acentos(x) {
    // version 040623
            // Spanish - Español
            // Portuguese - Portugués - Português
            // Italian - Italiano
            // French - Francés - Français
            // Also accepts and converts single and double quotation marks, square and angle brackets
            // and miscelaneous symbols.
            // Also accepts and converts html entities for all the above.
    //	if (navigator.appVersion.toLowerCase().indexOf("windows") != -1) {return x}
    x = x.replace(/¡/g,"\xA1");	x = x.replace(/&iexcl;/g,"\xA1");
    x = x.replace(/¿/g,"\xBF");	x = x.replace(/&iquest;/g,"\xBF");
    x = x.replace(/À/g,"\xC0");	x = x.replace(/&Agrave;/g,"\xC0");
    x = x.replace(/à/g,"\xE0");	x = x.replace(/&agrave;/g,"\xE0");
    x = x.replace(/Á/g,"\xC1");	x = x.replace(/&Aacute;/g,"\xC1");
    x = x.replace(/á/g,"\xE1");	x = x.replace(/&aacute;/g,"\xE1");
    x = x.replace(/Â/g,"\xC2");	x = x.replace(/&Acirc;/g,"\xC2");
    x = x.replace(/â/g,"\xE2");	x = x.replace(/&acirc;/g,"\xE2");
    x = x.replace(/Ã/g,"\xC3");	x = x.replace(/&Atilde;/g,"\xC3");
    x = x.replace(/ã/g,"\xE3");	x = x.replace(/&atilde;/g,"\xE3");
    x = x.replace(/Ä/g,"\xC4");	x = x.replace(/&Auml;/g,"\xC4");
    x = x.replace(/ä/g,"\xE4");	x = x.replace(/&auml;/g,"\xE4");
    x = x.replace(/Å/g,"\xC5");	x = x.replace(/&Aring;/g,"\xC5");
    x = x.replace(/å/g,"\xE5");	x = x.replace(/&aring;/g,"\xE5");
    x = x.replace(/Æ/g,"\xC6");	x = x.replace(/&AElig;/g,"\xC6");
    x = x.replace(/æ/g,"\xE6");	x = x.replace(/&aelig;/g,"\xE6");
    x = x.replace(/Ç/g,"\xC7");	x = x.replace(/&Ccedil;/g,"\xC7");
    x = x.replace(/ç/g,"\xE7");	x = x.replace(/&ccedil;/g,"\xE7");
    x = x.replace(/È/g,"\xC8");	x = x.replace(/&Egrave;/g,"\xC8");
    x = x.replace(/è/g,"\xE8");	x = x.replace(/&egrave;/g,"\xE8");
    x = x.replace(/É/g,"\xC9");	x = x.replace(/&Eacute;/g,"\xC9");
    x = x.replace(/é/g,"\xE9");	x = x.replace(/&eacute;/g,"\xE9");
    x = x.replace(/Ê/g,"\xCA");	x = x.replace(/&Ecirc;/g,"\xCA");
    x = x.replace(/ê/g,"\xEA");	x = x.replace(/&ecirc;/g,"\xEA");
    x = x.replace(/Ë/g,"\xCB");	x = x.replace(/&Euml;/g,"\xCB");
    x = x.replace(/ë/g,"\xEB");	x = x.replace(/&euml;/g,"\xEB");
    x = x.replace(/Ì/g,"\xCC");	x = x.replace(/&Igrave;/g,"\xCC");
    x = x.replace(/ì/g,"\xEC");	x = x.replace(/&igrave;/g,"\xEC");
    x = x.replace(/Í/g,"\xCD");	x = x.replace(/&Iacute;/g,"\xCD");
    x = x.replace(/í/g,"\xED");	x = x.replace(/&iacute;/g,"\xED");
    x = x.replace(/Î/g,"\xCE");	x = x.replace(/&Icirc;/g,"\xCE");
    x = x.replace(/î/g,"\xEE");	x = x.replace(/&icirc;/g,"\xEE");
    x = x.replace(/Ï/g,"\xCF");	x = x.replace(/&Iuml;/g,"\xCF");
    x = x.replace(/ï/g,"\xEF");	x = x.replace(/&iuml;/g,"\xEF");
    x = x.replace(/Ñ/g,"\xD1");	x = x.replace(/&Ntilde;/g,"\xD1");
    x = x.replace(/ñ/g,"\xF1");	x = x.replace(/&ntilde;/g,"\xF1");
    x = x.replace(/Ò/g,"\xD2");	x = x.replace(/&Ograve;/g,"\xD2");
    x = x.replace(/ò/g,"\xF2");	x = x.replace(/&ograve;/g,"\xF2");
    x = x.replace(/Ó/g,"\xD3");	x = x.replace(/&Oacute;/g,"\xD3");
    x = x.replace(/ó/g,"\xF3");	x = x.replace(/&oacute;/g,"\xF3");
    x = x.replace(/Ô/g,"\xD4");	x = x.replace(/&Ocirc;/g,"\xD4");
    x = x.replace(/ô/g,"\xF4");	x = x.replace(/&ocirc;/g,"\xF4");
    x = x.replace(/Õ/g,"\xD5");	x = x.replace(/&Otilde;/g,"\xD5");
    x = x.replace(/õ/g,"\xF5");	x = x.replace(/&otilde;/g,"\xF5");
    x = x.replace(/Ö/g,"\xD6");	x = x.replace(/&Ouml;/g,"\xD6");
    x = x.replace(/ö/g,"\xF6");	x = x.replace(/&ouml;/g,"\xF6");
    x = x.replace(/Ø/g,"\xD8");	x = x.replace(/&Oslash;/g,"\xD8");
    x = x.replace(/ø/g,"\xF8");	x = x.replace(/&oslash;/g,"\xF8");
    x = x.replace(/Ù/g,"\xD9");	x = x.replace(/&Ugrave;/g,"\xD9");
    x = x.replace(/ù/g,"\xF9");	x = x.replace(/&ugrave;/g,"\xF9");
    x = x.replace(/Ú/g,"\xDA");	x = x.replace(/&Uacute;/g,"\xDA");
    x = x.replace(/ú/g,"\xFA");	x = x.replace(/&uacute;/g,"\xFA");
    x = x.replace(/Û/g,"\xDB");	x = x.replace(/&Ucirc;/g,"\xDB");
    x = x.replace(/û/g,"\xFB");	x = x.replace(/&ucirc;/g,"\xFB");
    x = x.replace(/Ü/g,"\xDC");	x = x.replace(/&Uuml;/g,"\xDC");
    x = x.replace(/ü/g,"\xFC");	x = x.replace(/&uuml;/g,"\xFC");
    x = x.replace(/\"/g,"\x22");
    x = x.replace(/\'/g,"\x27");
    x = x.replace(/\</g,"\x3C");
    x = x.replace(/\>/g,"\x3E");
    x = x.replace(/\[/g,"\x5B");
    x = x.replace(/\]/g,"\x5D");
    x = x.replace(/¢/g,"\xA2");	x = x.replace(/&cent;/g,"\xA2");
    x = x.replace(/£/g,"\xA3");	x = x.replace(/&pound;/g,"\xA3");
    x = x.replace(/€/g,"\u20AC");	x = x.replace(/&euro;/g,"\u20AC");
    x = x.replace(/©/g,"\xA9");	x = x.replace(/&copy;/g,"\xA9");
    x = x.replace(/®/g,"\xAE");	x = x.replace(/&reg;/g,"\xAE");
    x = x.replace(/ª/g,"\xAA");	x = x.replace(/&ordf;/g,"\xAA");
    x = x.replace(/º/g,"\xBA");	x = x.replace(/&ordm;/g,"\xBA");
    x = x.replace(/°/g,"\xB0");	x = x.replace(/&deg;/g,"\xB0");
    x = x.replace(/±/g,"\xB1");	x = x.replace(/&plusmn;/g,"\xB1");
    x = x.replace(/×/g,"\xD7");	x = x.replace(/&times;/g,"\xD7");
    return x;
}

// Definicion de Funciones que funcionaran con AJAX
function newAjax(){
   var xmlhttp=null;

   try	{
		// Firefox, Opera 8.0+, Safari
 		xmlhttp=new XMLHttpRequest();
	} catch (e)  {
 		// Internet Explorer
 		try	{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  		} catch (e) {
  			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}

   	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    	xmlhttp = new XMLHttpRequest();
   	}
   return xmlhttp;
}

/*function cargarContenido(contenedor,exelink){
   var vContenedor;
   vContenedor = document.getElementById(contenedor);
	var vLoad='<div class=\"LoadingOut\"><b class=\"rtop\"><b class=\"r1\"></b> <b class=\"r2\"></b> <b class=\"r3\"></b> <b class=\"r4\"></b></b><div class=\"LoadingIn\"><br>Cargando Informaci&oacute;n...<br><img src=\"images/bigWaiting.gif\"><br></div><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div>';

   ajax=newAjax();
   ajax.open("GET", exelink,true);
   vContenedor.innerHTML=vLoad;
   ajax.onreadystatechange=function() {
                              if (ajax.readyState==4) {
			          vContenedor.innerHTML = acentos(ajax.responseText);
		              }
                           }
   ajax.send(null)
}*/

//function cargarContenidoExec(contenedor,exelink,funcname){
function cargarContenido(contenedor,exelink,funcname){
    var vContenedor;
        vContenedor = document.getElementById(contenedor);
    var vLoad='<div class=\"LoadingOut\"><b class=\"rtop\"><b class=\"r1\"></b> <b class=\"r2\"></b> <b class=\"r3\"></b> <b class=\"r4\"></b></b><div class=\"LoadingIn\"><br>Cargando Informaci&oacute;n...<br><img src=\"images/bigWaiting.gif\"><br></div><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div>';

   ajax=newAjax();
   ajax.open("GET", exelink,true);
   vContenedor.innerHTML=vLoad;
   ajax.onreadystatechange=function() {
        if (ajax.readyState==4 && ajax.status == 200) {
            //alert(ajax.responseText);
            var scs= ajax.responseText.extractScript();
            var res = ajax.responseText.stripScript();
            //alert(res);

            vContenedor.innerHTML = parseScript(acentos(res));
            scs.evalScript();

            if(funcname != null && funcname != '')
                eval(funcname);
        }
   }
   ajax.send(null)
}

function ejecutarRequest(exelink){
    ajax=newAjax();
    ajax.open("GET", exelink,true);
    ajax.onreadystatechange=function() {
      if (ajax.readyState==4 && ajax.status == 200) {
          //vContenedor.innerHTML = ajax.responseText;
      }
    }
    ajax.send(null);
}

function cargarContenido2(contenedor,exelink,contenedor2,exelink2){
   var vContenedor,vContenedor2;
   var vLoad='<div class=\"LoadingOut\"><b class=\"rtop\"><b class=\"r1\"></b> <b class=\"r2\"></b> <b class=\"r3\"></b> <b class=\"r4\"></b></b><div class=\"LoadingIn\"><br>Cargando Informaci&oacute;n...<br><img src=\"images/bigWaiting.gif\"><br></div><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div>';
   vContenedor = document.getElementById(contenedor);
   vContenedor2= document.getElementById(contenedor2);
   ajax=newAjax();
   ajax.open("GET", exelink,true);
   //vContenedor.innerHTML=vLoad;
   ajax.onreadystatechange=function() {
                              if (ajax.readyState==4 && ajax.status == 200) {
                                    //vContenedor.innerHTML = ajax.responseText;
                                    var scs= ajax.responseText.extractScript();
                                    var res = ajax.responseText.stripScript();
                                    //alert(res);

                                    vContenedor.innerHTML = parseScript(acentos(res));
                                    scs.evalScript();
                              }
                           }
   ajax.send(null);

   ajax2=newAjax();
   ajax2.open("GET",exelink2,true);
   vContenedor2.innerHTML=vLoad;
   ajax2.onreadystatechange=function(){
                               if(ajax2.readyState==4){
                                    //vContenedor2.innerHTML = ajax2.responseText;
                                    var scs= ajax2.responseText.extractScript();
                                    var res = ajax2.responseText.stripScript();
                                    //alert(res);

                                    vContenedor2.innerHTML = parseScript(acentos(res));
                                    scs.evalScript();
                               }
                            }
   ajax2.send(null);
}

function cargarContenidoDin(contenedor,exelink,formName,confirmacion,funcname){
        var vForm=document.getElementById(formName);
        var vSendPost="";
	var vLoad='<div class=\"LoadingOut\"><b class=\"rtop\"><b class=\"r1\"></b> <b class=\"r2\"></b> <b class=\"r3\"></b> <b class=\"r4\"></b></b><div class=\"LoadingIn\"><br>Cargando Informaci&oacute;n...<br><img src=\"images/bigWaiting.gif\"><br></div><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div>';

        for (i=0;i<vForm.elements.length;i++){
                var vType=vForm.elements[i].type;
                var vName=vForm.elements[i].name;

                //alert('tipo='+vType);
                switch (vType){
                        case "text":
                                var vValue=vForm.elements[i].value;
                                break;
                        case "password":
                                var vValue=vForm.elements[i].value;
                                break;
                        case "hidden":
                                var vValue=encodeURIComponent(vForm.elements[i].value);
                                break;
                        case "checkbox":
                                var vValue=0;
                                if (vForm.elements[i].checked==true) vValue=1;
                                break;
                        case "radio":
                                var vValue=0;
//alert(vForm.elements[i].value);
								//if (vForm.elements[i].checked==true) var vValue=vForm.elements[i].value;
								//var vValue=vForm.elements[i].value;
                                if (vForm.elements[i].checked==true) vValue=1;
                                break;
                        case "select-one":
                                var vValue=vForm.elements[i].value;
                                break;
                        case "submit":
                                var vValue="";
                                var vName="";
                                break;
                        case "textarea":
                             var vValue = vForm.elements[i].value;
                             break;
                }
                if (i>0 && i<(vForm.elements.length)) vSendPost=vSendPost+"&";
                vSendPost=vSendPost+vName+"="+vValue;
        }
//alert(vSendPost);
        var vContenedor = document.getElementById(contenedor);
        ajax=newAjax();

        if(typeof confirmacion==="undefined"){
                confirmacion=0;
        }

        var respuesta=true;
        if (confirmacion!=0){
                respuesta=window.confirm("Desea Continuar con el proceso?");
                //document.getElementById('apLocked').style.visibility="visible";
                //document.getElementById('apMensajesRes').style.visibility="visible";
        }

        if(respuesta){
                ajax.open("POST",exelink,true);

                //vContenedor.innerHTML='<p algin=center >Loading...<br><img src=\"images/bigWaiting.gif\"></p>';
                vContenedor.innerHTML=vLoad;
                ajax.onreadystatechange=function(){
                                     if(ajax.readyState==4 && ajax.status == 200){
                                        //vContenedor.innerHTML=ajax.responseText;
                                        var scs= ajax.responseText.extractScript();
                                        var res = ajax.responseText.stripScript();
                                        //alert(res);

                                        vContenedor.innerHTML = parseScript(acentos(res));
                                        scs.evalScript();
                                        if(funcname != null && funcname != "")
                                               eval(funcname);
                                        //vLoad.innerHTML='';
                                     }
                                  }

                ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                ajax.send(vSendPost);
        }
}

function validar_fecha()
{
	var fini = document.getElementById("fini");
    var ffin = document.getElementById("ffin");

    if(fini != null){
    alert(fini.value.length);
    	if(fini.value.length<10){

    		alert('Fecha de Inicio Invalida');
    		return false;
    	}
    }
    if(ffin != null){
    	if(ffin.value.length<10){
    		alert('Fecha de Fin Invalida');
    		return false;
    	}
    }
    return true;
}

function cargarContenidoPost(contenedor,exelink,p1,p2,p3,p4,p5,p6, funcname){

	/*var ingreso;
	ingreso=validar_fecha();
	//alert(ingreso);
   if(ingreso) {*/
	   var vP1,vP2,vP3,vP4,vP5,vP6,vContenedor,vLoad;
	   vContenedor=document.getElementById(contenedor);
	   vLoad='<div class=\"LoadingOut\"><b class=\"rtop\"><b class=\"r1\"></b> <b class=\"r2\"></b> <b class=\"r3\"></b> <b class=\"r4\"></b></b><div class=\"LoadingIn\"><br>Cargando Informaci&oacute;n...<br><img src=\"images/bigWaiting.gif\"><br></div><b class=\"rbottom\"><b class=\"r4\"></b> <b class=\"r3\"></b> <b class=\"r2\"></b> <b class=\"r1\"></b></b></div>';

	   vP1=document.getElementById(p1).value;
	   if(p2!=''){
               if(document.getElementById(p2) != null)
                    vP2=document.getElementById(p2).value;
               else if(document.getElementsByName(p2)[0] != null){
                   if(document.getElementsByName(p2)[0].getAttribute("type") == null){//es un select
                       vP2 = document.getElementsByName(p2)[0].options[document.getElementsByName(p2)[0].selectedIndex].value;
                   }else
                        vP2 = document.getElementsByName(p2)[0].value;
                   //alert(vP2);
               }
	   }
	   if (p3!=''){
	     vP3=document.getElementById(p3).value;
	   }
	   if(p4!=''){
	     vP4=document.getElementById(p4).value;
	   }
	   if(p5!=''){
	     vP5=document.getElementById(p5).value;
	   }
	   if(p6!=''){
	     vP6=document.getElementById(p6).value;
	   }


	   ajax=newAjax();

	   ajax.open("POST",exelink,true);
	   //vContenedor.innerHTML='<p algin=center >Loading...<br><img src=\"images/bigWaiting.gif\"></p>';
	   vContenedor.innerHTML=vLoad;
	   ajax.onreadystatechange=function(){
	                             if(ajax.readyState==4){
	                                //vContenedor.innerHTML=ajax.responseText;
                                        var scs= ajax.responseText.extractScript();
                                        var res = ajax.responseText.stripScript();
                                        //alert(res);

                                        vContenedor.innerHTML = parseScript(acentos(res));
                                        scs.evalScript();
	                                //vLoad.innerHTML='';
                                        if(funcname != null && funcname != "")
                                            eval(funcname);
	                             }
	                          }
	   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	   if(p2=='' && p3=='' && p4=='' && p5=='' && p6==''){
	      ajax.send(p1+"="+vP1);
	   }else if(p3=='' && p4=='' && p5=='' && p6==''){
	      ajax.send(p1+"="+vP1+"&"+p2+"="+vP2);
	   }else if(p4=='' && p5=='' && p6==''){
	      ajax.send(p1+"="+vP1+"&"+p2+"="+vP2+"&"+p3+"="+vP3);
	   }else if(p5=='' && p6==''){
	      ajax.send(p1+"="+vP1+"&"+p2+"="+vP2+"&"+p3+"="+vP3+"&"+p4+"="+vP4);
	   }else if(p6==''){
	      ajax.send(p1+"="+vP1+"&"+p2+"="+vP2+"&"+p3+"="+vP3+"&"+p4+"="+vP4+"&"+p5+"="+vP5);
	   }else{
	      ajax.send(p1+"="+vP1+"&"+p2+"="+vP2+"&"+p3+"="+vP3+"&"+p4+"="+vP4+"&"+p5+"="+vP5+"&"+p6+"="+vP6);
	   }
	/*}else alert(' jj')*/
}

function pagina(contenedor, link){
	var select = document.getElementById("paginador");
	var seleccionado = select.options[select.selectedIndex].text;
	cargarContenido(contenedor, link+seleccionado, '');
}
//window.onload= function(){cargarContenido()}
function parseScript(_source) {
     var source = _source;
     var scripts = new Array();

     // Strip out tags
     while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
          var s = source.indexOf("<script");
          var s_e = source.indexOf(">", s);
          var e = source.indexOf("</script", s);
          var e_e = source.indexOf(">", e);

          // Add to scripts array
          scripts.push(source.substring(s_e+1, e));
          // Strip from source
          source = source.substring(0, s) + source.substring(e_e+1);
     }

     // Loop through every script collected and eval it
     for(var i=0; i<scripts.length; i++) {
          try {
               eval(scripts[i]);
          }
          catch(ex) {
               // do what you want here when a script fails
          }
     }

     // Return the cleaned source
     return source;
}